package com.kdg.Operator;

/**
 * JAVA运算符
 * Created by kong on 2018/5/25.
 */
public class OperatorTest {
    public static void main(String[] args) {
        //1.位运算--与   相同1则为1   否则为0   双目运算符
        Integer a = 130, b = 10;
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制b " + Integer.toBinaryString(b));
        System.out.println("a & b 之后为" + (a & b));
        System.out.println("a &= b 之后为" + (a &= b));
        //2.位运算--或   有1就是1  全是0才是0  双目运算符
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制b " + Integer.toBinaryString(b));
        System.out.println("a | b 之后为" + (a | b));
        System.out.println("a | b 之后为" + (a |= b));
        //3.位运算--异或   不同为1  否则为0  双目运算符
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制b " + Integer.toBinaryString(b));
        System.out.println("a ^ b (异或)之后为" + (a ^ b));
        System.out.println("a ^= b (异或)之后为" + (a ^ b));
        //4.位运算--非 ~   ????????????  单目运算符
        System.out.println("二进制b " + Integer.toBinaryString(b));
        System.out.println("~b 之后为" + (~2));

        //5.位移运算符-- 带符号右位移 >>  双目运算符
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制a右位移1位后的二进制" + Integer.toBinaryString(a >> 1));
        System.out.println(a >> 1);
        System.out.println(Integer.toBinaryString(-2 >> 1) + "     "  + (-2>>1));
        //6.位移运算符-- 带符号左位移 <<  双目运算符
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制a左位移1位后的二进制" + Integer.toBinaryString(a << 1));
        System.out.println(a << 1);
        //7.位移运算符-- 无符号左位移 <<<  单目运算符
        System.out.println("二进制a " + Integer.toBinaryString(a));
        System.out.println("二进制a左位移1位后的二进制" + Integer.toBinaryString(a << 1));
        System.out.println(a << 1);
        System.out.println(Integer.toBinaryString(-2 >>> 1) + "     "  + (-2 >>> 1));

    }
}
